package logic

import (
	"context"
	"shopexam/model/redis"

	"shopexam/shoprpc/internal/svc"
	"shopexam/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopLikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopLikeListLogic {
	return &ShopLikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopLikeListLogic) ShopLikeList(in *shoprpc.ShopLikeListRequest) (*shoprpc.ShopLikeListResponse, error) {
	// todo: add your logic here and delete this line
	s := redis.Rdb.ZRevRangeWithScores("shop-list", 0, 9)
	var list []*shoprpc.ShopLikeList
	for _, z := range s.Val() {
		list1 := shoprpc.ShopLikeList{
			Like: int64(z.Score),
			Name: z.Member.(string),
		}
		list = append(list, &list1)
	}
	return &shoprpc.ShopLikeListResponse{List: list}, nil
}
